#ifndef _ENTITY_H_
#define _ENTITY_H_

#include "../stdafx.h"

#include "../math/sse/quaternion.h"
#include "../math/sse/vector.h"

#include "../memory/datablock.h"


using namespace sse_math;

struct DataBlockList
{
public:
	DataBlock<CVector3> position;
	DataBlock<CQuaternion> orientation;
	DataBlockList(unsigned int size):position(size), orientation(size){}
};

typedef unsigned long entityID;

class CEntity
{
private:
	DataBlockList * _datablocks;
	entityID _id;
public:
	CEntity(entityID id, DataBlockList * datablocks):_id(id), _datablocks(datablocks){}
	inline const CVector3 & position() const {return _datablocks->position[_id];}
	inline CVector3 & position() {return _datablocks->position[_id];}
	inline const CQuaternion & orientation() const {return _datablocks->orientation[_id];}
	inline CQuaternion & orientation() {return _datablocks->orientation[_id];}
	virtual void collide(CEntity & target) = 0;
};

class CPlane : public CEntity
{
private:
	unsigned long hitpoints;
public:
	CPlane(entityID id, DataBlockList * datablocks):CEntity(id, datablocks), hitpoints(100){}
	virtual void collide(CEntity & target)
	{
	}
};

/*
	Class CEntityManager, holds data representations of entities, and performs
	vectorized operations on groups of entities.
*/

class CEntityManager
{
private:
	static CEntityManager * _inst;

protected:
	CEntityManager(){};
	CEntityManager(const CEntityManager & r);
	CEntityManager & operator = (const CEntityManager & r);

public:
	inline static CEntityManager * create() {return (_inst = new CEntityManager());}
	inline static CEntityManager * getInstance() {return _inst;}

	static DataBlockList planes;
};

#endif // _ENTITY_H_